home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
M2Crypto
/
httpslib.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
5KB
|
173 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import string
import sys
import socket
import urllib
import base64
from httplib import *
from httplib import HTTPS_PORT
import SSL
class HTTPSConnection(HTTPConnection):
default_port = HTTPS_PORT
def __init__(self, host, port = None, strict = None, **ssl):
self.session = None
keys = ssl.keys()
try:
keys.remove('key_file')
except ValueError:
pass
try:
keys.remove('cert_file')
except ValueError:
pass
try:
keys.remove('ssl_context')
except ValueError:
pass
if keys:
raise IllegalKeywordArgument()
try:
self.ssl_ctx = ssl['ssl_context']
except KeyError:
self.ssl_ctx = SSL.Context('sslv23')
HTTPConnection.__init__(self, host, port, strict)
def connect(self):
self.sock = SSL.Connection(self.ssl_ctx)
if self.session:
self.sock.set_session(self.session)
self.sock.connect((self.host, self.port))
def close(self):
pass
def get_session(self):
return self.sock.get_session()
def set_session(self, session):
self.session = session
class HTTPS(HTTP):
_connection_class = HTTPSConnection
def __init__(self, host = '', port = None, strict = None, **ssl):
HTTP.__init__(self, host, port, strict)
try:
self.ssl_ctx = ssl['ssl_context']
except KeyError:
self.ssl_ctx = SSL.Context('sslv23')
self._conn.ssl_ctx = self.ssl_ctx
class ProxyHTTPSConnection(HTTPSConnection):
_ports = {
'http': 80,
'https': 443 }
_AUTH_HEADER = 'Proxy-Authorization'
def __init__(self, host, port = None, strict = None, username = None, password = None, **ssl):
HTTPSConnection.__init__(self, host, port, strict, **ssl)
self._username = username
self._password = password
self._proxy_auth = None
def putrequest(self, method, url, skip_host = 0, skip_accept_encoding = 0):
(proto, rest) = urllib.splittype(url)
if proto is None:
raise ValueError, 'unknown URL type: %s' % url
(host, rest) = urllib.splithost(rest)
(host, port) = urllib.splitport(host)
if port is None:
try:
port = self._ports[proto]
except KeyError:
raise ValueError, 'unknown protocol for: %s' % url
except:
None<EXCEPTION MATCH>KeyError
None<EXCEPTION MATCH>KeyError
self._real_host = host
self._real_port = port
HTTPSConnection.putrequest(self, method, url, skip_host, skip_accept_encoding)
def putheader(self, header, value):
if header.lower() == self._AUTH_HEADER.lower():
self._proxy_auth = value
else:
HTTPSConnection.putheader(self, header, value)
def endheaders(self):
if not self._proxy_auth:
self._proxy_auth = self._encode_auth()
HTTPSConnection.endheaders(self)
def connect(self):
HTTPConnection.connect(self)
self.sock.sendall(self._get_connect_msg())
response = HTTPResponse(self.sock)
response.begin()
code = response.status
if code != 200:
self.close()
raise socket.error, 'Proxy connection failed: %d' % code
self._start_ssl()
def _get_connect_msg(self):
msg = 'CONNECT %s:%d HTTP/1.1\r\n' % (self._real_host, self._real_port)
if self._proxy_auth:
msg = msg + '%s: %s\r\n' % (self._AUTH_HEADER, self._proxy_auth)
msg = msg + '\r\n'
return msg
def _start_ssl(self):
self.sock = SSL.Connection(self.ssl_ctx, self.sock)
self.sock.setup_ssl()
self.sock.set_connect_state()
self.sock.connect_ssl()
def _encode_auth(self):
if not self._username and self._password:
return None
userpass = '%s:%s' % (self._username, self._password)
enc_userpass = base64.encodestring(userpass).replace('\n', '')
return 'Basic %s' % enc_userpass